package com.icecloud.cloud.filestore.common;

import org.apache.commons.lang.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 基类
 * 统一处理异常，类型转化
 * @author penghaozhong
 *
 */
@ControllerAdvice
public class BaseController {
	
	@ExceptionHandler(Exception.class)
	public ResponseEntity<? extends RestfulResponseBody> handleaseExceptions(Exception e) {
		RestfulResponseBody body = new RestfulResponseBody();
		if(StringUtils.isNotBlank(e.getMessage())){
			body.setReason(e.getMessage());
		}else{
			body.setReason("系统错误,请联系管理员!");
		}
		body.setResultFlag(HttpStatus.EXPECTATION_FAILED.value());
		e.printStackTrace();
		return  new ResponseEntity<RestfulResponseBody>(body, HttpStatus.EXPECTATION_FAILED);

	}

}
